<?php

namespace App\V3\V3_2_6\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class ProductFillOrBalanceContentModel extends Model
{


    use HasFactory;

    protected $table   = 'product_fill_or_balance_content';
    protected $dateFormat = 'U';//这个时间字段被为被格式化为UNIX 时间戳的形式存储

    public static function getProductFillOrBalanceInfo($id, $type)
    {
        return ProductFillOrBalanceContentModel::select(
            'a.serial_id',
            'a.type_id',
            'b.materiel_name',
            'b.type_name',
            'b.materiel_unit',
            'a.type',
            'serial_no',
            'g.storage_name',
            'a.num',
            'b.is_use_serial',
            'd.shelf_name',
            'e.location_name',
            'a.shelf_id',
            'a.location_id'
        )
            ->from('product_fill_or_balance_content as a')
            ->leftJoin('materiel_type as b', 'b.id', '=', 'a.type_id')
            ->leftJoin('storage_manage as c', 'c.id', '=', 'a.storage_manage_id')
            ->leftJoin('storage_shelf as d', 'd.id', '=', 'c.shelf_id')
            ->leftJoin('storage_shelf_location as e', 'e.id', '=', 'c.location_id')
            ->leftJoin('serial_number as f', 'f.id', '=', 'a.serial_id')
            ->leftJoin('storage as g', 'g.id', '=', 'c.storage_id')
            ->where('product_order_id', $id)
            ->where('type', $type)
            ->get()->toArray();
    }
}
